package com.dc.refactoring._6_处理概括关系._10_FormTemplateMethod.step2;

import com.dc.refactoring._0_入门.Rental;

public class TextStatement extends Statement {

    /**
     * 普通打印会话
     */
    public String value(Customer customer) {
        String result = headerString(customer);
        for (Rental rental : customer.getRentals()) {
            // 展示电影明细
            result += eachRentalString(rental);
        }
        result += footerString(customer);
        return result;
    }



    // step 1 将函数中不同的部分进行提炼，从而将相似的代码和变动的代码分开
    private String headerString(Customer customer) {
        return customer.getName() + "的租赁记录信息为：\n";
    }

    private String eachRentalString(Rental rental) {
        return "\t" + rental.getMovie().getTitle() + "\t" + rental.getCharge() + "\n";
    }

    private String footerString(Customer customer) {
        return  "总金额为：" + customer.getTotalCharge() + "\n"
                + "你获得的积分为：" + customer.getTotalFrequentRenterPoints() + "\n";
    }

}
